<template>
  <div class="main">
    <div class="view">
      <FaceRoot
        ref="FaceRootDia"
        :loading="loading"
        :formData="formDataDia"
        :selectList="selectListDia"
        :form="formDia"
        :statu="true"
      />
    </div>
  </div>
</template>
<script>
import { getEditDataApi, getFacerootApi } from '@/api/Ledger'
import FaceRoot from '@/views/Ledger/components/FaceRoot.vue'
export default {
  name: 'LedgerView',
  components: { FaceRoot },
  props: {
    viewObj: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    viewObj: {
      handler (val) {
        console.log(val)
      },
      immediate: true,
      deep: true
    }
  },
  data () {
    return {
      entityId: '',
      className: '',
      formDataDia: {},
      selectListDia: {},
      formDia: {},
      loading: false
    }
  },
  async mounted () {
    if (this.viewObj?.name) {
      this.entityId = this.viewObj.id
      this.className = this.viewObj.name
    } else {
      this.entityId = this.$route.params.entityId
      this.className = this.$route.params.className
    }
    // await this.chushihuaDia()
    await this.getData()
  },
  methods: {
    // async chushihuaDia () {
    //   this.handleClose()
    //   this.loading = true
    //   const res = await getFacerootApi({
    //     className: this.className
    //   })
    //   this.formDia = res?.data.entity
    //   if (this.className !== 'Root') {
    //     const res1 = await getViewDataApi({
    //       entityId: this.entityId,
    //       className: this.className
    //     })
    //     this.$nextTick(() => {
    //       this.formDataDia = res1?.data.entity?.valueMap
    //       this.selectListDia = res1?.data.entity?.elementComboItemMap
    //     })
    //   }
    //   this.loading = false
    // },
    async getData () {
      this.loading = true
      const res = await getEditDataApi({
        entityId: this.entityId,
        className: this.className
      })
      const res1 = await getFacerootApi({
        className: this.className
      })
      this.formDia = res1?.data.entity
      this.formDataDia = res?.data.entity?.valueMap
      this.selectListDia = res?.data.entity?.elementComboItemMap
      this.$nextTick(() => {
        this.$refs.FaceRootDia.preview = true
        console.log(this.$refs.FaceRootDia.preview)
      })
      this.loading = false
    },
    handleClose () {
      this.formDataDia = {}
      this.selectListDia = {}
    }
  }
}
</script>

<style lang="scss" scoped>
.main {
    width: 100%;

    display: flex;
    justify-content: center;
  .view {
    width: 1000px;
    min-height: 100vh;
    background-color: #fff;
    padding: 20px;
  }
}
</style>
